package cn.fl.product.service.impl;

import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.product.service.ISplBiApplyFlowService;
import cn.fl.product.transform.SplBiApplyFlowRlVOTransform;
import cn.fl.product.vo.SplBiApplyFlowRlVO;
import fl.spl.facade.spl.api.ISplInfoApplyAddApiService;
import fl.spl.facade.spl.api.ISplInfoApplyApiService;
import fl.spl.facade.spl.api.ISplInfoApplyModifyApiService;
import fl.spl.facade.spl.condition.SplBiApplyFlowRlQC;
import fl.spl.facade.spl.dto.SplBiApplyFlowRlDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SplBiApplyFlowServiceImpl implements ISplBiApplyFlowService {

    @Autowired
    private ISplInfoApplyApiService splInfoApplyApiService;

    @Autowired
    private ISplInfoApplyAddApiService splInfoApplyAddApiService;

    @Autowired
    private ISplInfoApplyModifyApiService splInfoApplyModifyApiService;

    @Override
    public List<SplBiApplyFlowRlVO> getSplApplyFlow(Long applyId) {
        SplBiApplyFlowRlQC entity = new SplBiApplyFlowRlQC();
        entity.setSplApplyId(applyId);
        List<SplBiApplyFlowRlDTO> list = this.splInfoApplyApiService.getSplFlowApplyList(entity);
        return SplBiApplyFlowRlVOTransform.toVOList(list);
    }

    @Override
    public boolean saveSplApplyFlow(SplBiApplyFlowRlVO vo) {
        if (StringUtils.isEmpty(vo.getId())) {
            Long id = this.splInfoApplyAddApiService.addSplBiApplyFlow(SplBiApplyFlowRlVOTransform.toDTO(vo));
            if (id > 0) {
                vo.setId(id);
                return true;
            } else {
                return false;
            }
        } else {
            return this.splInfoApplyModifyApiService.modifySplBiApplyFlow(SplBiApplyFlowRlVOTransform.toDTO(vo));
        }
    }
}
